package com.cn.ZhiKeDianShang.util.PaoMaDeng;

import android.content.Context;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.cn.ZhiKeDianShang.R;
import com.cn.ZhiKeDianShang.model.response.IndexBean;

import java.util.List;

public class InnerAdapter extends RecyclerView.Adapter<InnerAdapter.MarqueHolder> {
    private List<IndexBean.AnnouncementBean> mData;
    private int size;
    private LayoutInflater mLayoutInflater;
    onItemClick mOnItemClick;

    public InnerAdapter(Context context, List<IndexBean.AnnouncementBean> data, onItemClick onItemClick) {
        mData = data;
        size = mData.size();
        mOnItemClick = onItemClick;
        mLayoutInflater = LayoutInflater.from(context);
    }

    @Override
    public MarqueHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = mLayoutInflater.inflate(R.layout.marque_item, parent, false);

        return new MarqueHolder(view);
    }

    public void setdate(List<IndexBean.AnnouncementBean> mDat){
        this.mData=mDat;
        notifyDataSetChanged();
    }

    @Override
    public void onBindViewHolder(MarqueHolder holder, int position) {
        if (mData.size()>0){
            holder.tv.setText(mData.get(position % size).getTitle());
            holder.tv_ll.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mOnItemClick.onItemClick(position % size);
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return Integer.MAX_VALUE;
    }

    /**
     * * ViewHolder类
     **/
    static class MarqueHolder extends RecyclerView.ViewHolder {
        TextView tv;
        LinearLayout tv_ll;

        public MarqueHolder(View view) {
            super(view);
            tv = (TextView) view.findViewById(R.id.tv);
            tv_ll = (LinearLayout) view.findViewById(R.id.tv_ll);
        }

    }

    public interface onItemClick {
        void onItemClick(int position);
    }

}

